package ruifeng.zcj.dig.ui.shopping;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import java.io.Serializable;

import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewHolder;
import cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper;
import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.base.api.OSChinaApi;
import ruifeng.zcj.dig.base.bean.Base;
import ruifeng.zcj.dig.groble.FragmentArgs;
import ruifeng.zcj.dig.groble.ToActivityUtil;
import ruifeng.zcj.dig.ui.home.MainActivity2;
import ruifeng.zcj.dig.ui.shopping.bean.Category;
import ruifeng.zcj.mybase.base.App;
import ruifeng.zcj.mybase.base.utils.GlideUtil;
import ruifeng.zcj.mybase.base.utils2.AbJsonUtil;
import ruifeng.zcj.mybase.base.utils2.CacheManager;

/**
 * 商品的一级分类
 * Created by Administrator on 2016/9/29 0029.
 */
public class OneCategoryFragment extends CategoryFragment{

    private static final String CACHE_KEY_PREFIX = "OneCategoryFragment";
    Category category = null;

    @Override
    protected BGARecyclerViewAdapter getAdapter() {
        return new MomentAdapter(recyclerView);
    }

    @Override
    protected String getCacheKeyPrefix() {
        return CACHE_KEY_PREFIX;
    }

    /***
     * 把数据显示到view上面去
     **/
    @Override
    protected void executeOnLoadDataSuccess(Serializable seri) {
        super.executeOnLoadDataSuccess(seri);
        category  = (Category) seri;
        if (mMomentAdapter != null) {
            mMomentAdapter.addNewData(category.getRows());
        }
    }



    @Override
    protected int categoryType() {
        return 0;
    }

    @Override
    protected Base fromJson(String netResult) {
        return (Category) AbJsonUtil.fromJson(netResult, Category.class);
    }


    public class MomentAdapter extends BGARecyclerViewAdapter<Category.RowsBean> {
        public MomentAdapter(RecyclerView recyclerView) {
            super(recyclerView, R.layout.listview_item_category);
        }

        @Override
        public void fillData(BGAViewHolderHelper helper, int position, Category.RowsBean moment) {
            /*if (TextUtils.isEmpty(moment.content)) {
                helper.setVisibility(R.id.tv_item_moment_content, View.GONE);
            } else {
                helper.setVisibility(R.id.tv_item_moment_content, View.VISIBLE);
                helper.setText(R.id.tv_item_moment_content, moment.content);
            }*/
            ImageView imageView = helper.getImageView(R.id.vehicle_fragment_item_img);

            GlideUtil.loadImage(mContext, String.format("http://kw.runfkj.com%s", moment.getPhoto()), imageView);

            helper.setText(R.id.vehicle_fragment_item_title, " "+moment.getSuppliertype());
            helper.setText(R.id.vehicle_fragment_item_address, "齿轮总成/星星齿");

          /*
            /*TextView postingsname = helper.getView(R.id.forum_fragment_item_text_title);

            BGANinePhotoLayout ninePhotoLayout = helper.getView(R.id.npl_item_moment_photos);

            ninePhotoLayout.init(MomentListActivity.this);
            ninePhotoLayout.setDelegate(MomentListActivity.this);
            ninePhotoLayout.setData(moment.photos);*/
        }

        @Override
        public void onViewRecycled(BGARecyclerViewHolder holder) {
            super.onViewRecycled(holder);

           /* BGANinePhotoLayout ninePhotoLayout = holder.getViewHolderHelper().getView(R.id.npl_item_moment_photos);
            ninePhotoLayout.init(null);
            ninePhotoLayout.setDelegate(null);*/
        }
    }

    @Override
    public void onRVItemClick(ViewGroup parent, View itemView, int position) {
        if (category != null){
            Category.RowsBean rowsBean = category.getRows().get(position);
            FragmentArgs fragmentArgs2 = new FragmentArgs();
            fragmentArgs2.add("category", rowsBean);
            ToActivityUtil.toNextActivity(getContext(), ShoppingActivity.class, "categoryBundle", fragmentArgs2);

//            showSnackBar("itme=位置"+rowsBean.getSupplierid());
        }

    }

    @Override
    public boolean onRVItemLongClick(ViewGroup parent, View itemView, int position) {
        return false;
    }

}
